/*
 * Push Button Test
 *
 */
 
#define LED_PIN 13         
#define INTERRUPT_NUM 1       // This identifies the interrupt number for
                              // our chipset:
                              //   0 = digial pin 2
                              //   1 = digital pin 3
                              
#define BUTTON_PIN 3          // set up the button pin to match the interrupt
                              // number.
#define DRIVER_PIN 4          // set up the a pin drive the button

volatile int led_state = LOW; // identify the current LED state
                              // this is volatile because the toggleLed
                              // routine which changes the value will be
                              // called from an interrupt. 

void toggleLed()
{
  // read in the current state of the button
  // and enable the LED state based on the button state
  led_state=digitalRead(BUTTON_PIN);
  
  // write the new state out to the LED pin
  digitalWrite(LED_PIN, led_state);
}


void setup()
{
  // set up the same LED as we have been
  pinMode(LED_PIN, OUTPUT);
  
  // add the driver pin
  pinMode(DRIVER_PIN, OUTPUT);
  // set the driver pin to LOW
  digitalWrite(DRIVER_PIN, LOW);
  
  // add the driver pin
  pinMode(BUTTON_PIN, INPUT);
  // enable the pull-up register
  digitalWrite(BUTTON_PIN, HIGH);
  
  // Identify the routine and conditions for our interrupt. An interrupt
  // can have only one routine attached, and that routine takes no inputs
  // and returns no output.  The specified routine will be called in 
  // the midst of the normal loop processing, so any variables that are
  // changed should probably be marked as volatile, if they are real-time
  // critical.  For our purposes, it's not necessary, but it may be 
  // significant if we have more robust processing of data changed in an 
  // interrupt routine.
  attachInterrupt(INTERRUPT_NUM, toggleLed, CHANGE); 
}

void loop()
{
  // nothing to do here, since it's all taken care of in the interrupt
}

